package com.zhiyin.seal.service.impl;

import com.zhiyin.seal.dao.ElectronicFenceDao;
import com.zhiyin.seal.entity.ElectronicFenceEntity;
import com.zhiyin.seal.entity.bo.ElectronicFenceBo;
import com.zhiyin.seal.entity.bo.ElectronicFenceDetailBo;
import com.zhiyin.seal.service.ElectronicFenceService;
import com.zhiyin.seal.util.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ElectronicFenceImpl implements ElectronicFenceService {

    @Autowired
    ElectronicFenceDao electronicFenceDao;

    @Override
    public Long addElectronicFence(ElectronicFenceBo electronicFenceBo) {
        ElectronicFenceEntity electronicFenceEntity = BeanUtil.copy(electronicFenceBo,ElectronicFenceEntity.class);
        electronicFenceDao.insertElectronicFence(electronicFenceEntity);
        return electronicFenceEntity.getId();
    }

    @Override
    public Boolean addElectronicFenceDetail(Long elecId, List<Long> sealIds) {
        return electronicFenceDao.insertElectronicFenceDetail(elecId,sealIds) > 0;
    }

    @Override
    public ElectronicFenceBo getElectronicFenceById(Long electronicFenceId) {
        ElectronicFenceEntity electronicFenceEntity = electronicFenceDao.selectCompanyElectronicFenceById(electronicFenceId);
        if(electronicFenceEntity != null){
            return BeanUtil.copy(electronicFenceEntity,ElectronicFenceBo.class);
        }

        return null;
    }

    @Override
    public List<ElectronicFenceBo> getElectronicFenceList(Long companyId) {
        return BeanUtil.copyList(electronicFenceDao.selectCompanyElectronicFenceList(companyId),ElectronicFenceBo.class);
    }

    @Override
    public List<ElectronicFenceBo> getElectronicFenceListBySeal(Long sealId) {
        return BeanUtil.copyList(electronicFenceDao.selectElectronicFenceListBySeal(sealId),ElectronicFenceBo.class);
    }

    @Override
    public List<ElectronicFenceDetailBo> getElectronicFenceDetail(Long electronicFenceId) {
        return BeanUtil.copyList(
                electronicFenceDao.selectElectronicFenceDetailList(electronicFenceId),ElectronicFenceDetailBo.class);
    }

    @Override
    public Boolean removeElectronicFenceBySealId(Long sealId) {
        return electronicFenceDao.deleteElectronicFenceBySealId(sealId) > 0;
    }

    @Override
    public Boolean removeElectronicFenceById(Long electronicFenceId) {
        return electronicFenceDao.deleteElectronicFenceById(electronicFenceId) > 0;
    }
}
